import React from "react";
import { Button, Modal, Table } from "antd";
import { messages, queryCurrencyPrecision } from "share/common";
import corporatePaymentReportService from "containers/corporate-payment-report/corporate-payment-report.service";

class WriteOffListModal extends React.Component {
  columns = [
    {
      title: messages("finance-9.key8") /*对公支付单号*/,
      dataIndex: "businessCode",
      width: 150,
    },
    {
      title: messages("common.currency") /*币种*/,
      dataIndex: "currencyCode",
      width: 80,
    },
    {
      title: messages("finance-9.key9") /*核销金额*/,
      dataIndex: "writeOffAmount",
      render: (value, record) => this.filterMoney(value, queryCurrencyPrecision(record.currencyCode)),
      width: 200,
    },
  ];

  state = {
    loading: false,
    writeOffList: [],
  };

  componentDidMount() {
    const { paymentScheduleId } = this.props;
    paymentScheduleId &&
      corporatePaymentReportService.getWriteOffHistoryList(paymentScheduleId).then((res) => {
        this.setState({
          writeOffList: res.data || [],
        });
      });
  }

  render() {
    const { writeOffList, loading } = this.state;
    const { visible, onCancel } = this.props;
    return (
      <Modal
        visible={visible}
        onCancel={onCancel}
        width={1000}
        title={messages("finance-9.key148") /*核销记录*/}
        footer={<Button onClick={onCancel}>{messages("common.cancel") /*取消*/}</Button>}
      >
        <Table
          rowKey="id"
          columns={this.columns}
          dataSource={writeOffList}
          size="small"
          bordered
          loading={loading}
          pagination={false}
        />
      </Modal>
    );
  }
}

export default WriteOffListModal;
